/**
 * 
 */
package com.tiduyun.data.exchange.service.impl;

import java.io.IOException;
import java.util.Map;
import java.util.Objects;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Service;

import com.tiduyun.data.exchange.model.GxVehicleDataExchangeResult;
import com.tiduyun.data.exchange.model.LoadTestGxVehicleDataExchangeResult;

import lombok.extern.slf4j.Slf4j;

/**
 * @author wuzheng@tiduyun.com
 *
 */
@Service("loadTestGxVehicleDataExchangeGatewayServiceImpl")
@Slf4j
public class LoadTestGxVehicleDataExchangeGatewayServiceImpl extends GxVehicleDataExchangeGatewayServiceImpl {

    @PostConstruct
    public void initService() throws IOException {
        super.initService();
        setIgnoreCommonCheckError(true);
    }

    @SuppressWarnings("unchecked")
    protected GxVehicleDataExchangeResult wrapResult(Map<String, Object> queryParams, Object result) {
        GxVehicleDataExchangeResult r = super.wrapResult(queryParams, result);
        LoadTestGxVehicleDataExchangeResult ltr = new LoadTestGxVehicleDataExchangeResult();
        ltr.setSign(r.getSign());
        ltr.setResponse(r.getResponse());
        ltr.setUtcTimestamp(r.getUtcTimestamp());
        if (result instanceof Map) {
            Map<String, Object> resultMap = (Map<String, Object>) result;
            String bizResult = Objects.toString(resultMap.get("biz_result"));
            ltr.setBizResult(bizResult);
            log.info("Load test response biz result: {}", bizResult);
        }
        return ltr;
    }

}
